package com.hyt.it.ogt.ks.enums.log;

import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author wuyingge
 * @version 1.0.0
 * @ClassName ExaminationOperatorType.java
 * @Description 监考员操作小类型
 * @createTime 2022年11月25日 09:50:00
 */
@Getter
public enum AdminOperatorLogType {

    ID_CHECK_PASSED(401, "人脸核身跳过"),
    DEVICE_CHECK_PASSED(402, "设备检测跳过"),
    CANCEL_SUBMIT(403, "撤销交卷"),
    ADD_SUB_TIME(404, "加减时"),
    RESEAT_LOGIN_TIME(405, "重置答题次数"),
    FORCE_SUBMIT(406, "强制收卷"),
    FINISH_ALL_EXAM(407, "结束整场考试"),
    PHOTO_COM_PASSED(408, "照片比对跳过"),
    EDIT_CANDIDATE_INFO(409, "修改信息"),
    LATE_ALLOW_LOGIN(410, "迟到允许登录"),
    CANCEL_OPEN_TIMEING(411, "重置答题时长")
    ;

    private Integer code;
    private String msg;

    public static String getMsg(Integer code) {
        for (AdminOperatorLogType value : AdminOperatorLogType.values()) {
            if(value.getCode().equals(code)) {
                return value.getMsg();
            }
        }
        return null;
    }

    AdminOperatorLogType(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static List<AdminOperatorLogType> listApplyChecks() {
        return Arrays.stream(AdminOperatorLogType.values()).filter(e -> isCheckType(e.getCode())).collect(Collectors.toList());
    }

    public static List<AdminOperatorLogType> listExceptionManages() {
        // 结束整场考试不需要展示在页面
        return Arrays.stream(AdminOperatorLogType.values()).filter(e -> !Objects.equals(407, e.getCode())).collect(Collectors.toList());
    }

    public static boolean isCheckType(int code) {
        return code == 401 || code == 402;
    }

    public static int getCodeByMsg(String msg) {
        return Arrays.stream(AdminOperatorLogType.values())
                .filter(e -> Objects.equals(e.getMsg(), msg))
                .findAny()
                .orElseThrow(() -> new IllegalArgumentException("错误的msg：" + msg))
                .getCode();
    }

    public static String getMsgByCode(int code) {
        return Arrays.stream(AdminOperatorLogType.values())
                .filter(e -> Objects.equals(e.getCode(), code))
                .findAny()
                .orElseThrow(() -> new IllegalArgumentException("错误的code：" + code))
                .getMsg();
    }
}
